package com.sgb.kjwl.view.ui.activity.enterprise;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMakeOverDetailBinding;
import com.sgb.kjwl.databinding.ActivityMakeOverPublishDetailBinding;
import com.sgb.kjwl.view.ui.fragment.enterprise.CompanyAlreadyPublishFragment;
import com.sgb.kjwl.view.ui.fragment.enterprise.CopyrightAlreadyPublishFragment;
import com.sgb.kjwl.view.ui.fragment.enterprise.PatentAlreadyPublishFragment;
import com.sgb.kjwl.view.ui.fragment.enterprise.PropertyAlreadyPublishFragment;
import com.sgb.kjwl.view.ui.fragment.enterprise.TradeAlreadyPublishFragment;
import com.sgb.kjwl.view.ui.fragment.enterprise.TradePublishFragment;
import com.sgb.kjwl.viewmodel.enterprise.PublishViewModel;

public class MakeoverPublishDetailActivity extends AppActivity {

    ActivityMakeOverPublishDetailBinding mBinding;
    PublishViewModel mViewModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_make_over_publish_detail);
        mBinding.setLifecycleOwner(this);
        mViewModel = new ViewModelProvider(this).get(PublishViewModel.class);

        int type = getIntent().getIntExtra("type",0);
        long id = getIntent().getLongExtra("id",0);

        mBinding.actionBar.setOnBackClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        switch (type){
            case 0:
                mBinding.actionBar.setTitle("商标转让");
                fragmentTransaction.replace(R.id.rl_makeover_publish_up_content, TradeAlreadyPublishFragment.newInstance(id));
                break;
            case 1:
                mBinding.actionBar.setTitle("专利转让");
                fragmentTransaction.replace(R.id.rl_makeover_publish_up_content, PatentAlreadyPublishFragment.newInstance(id));
                break;
            case 2:
                mBinding.actionBar.setTitle("版权转让");
                fragmentTransaction.replace(R.id.rl_makeover_publish_up_content, CopyrightAlreadyPublishFragment.newInstance(id));
                break;
            case 3:
                mBinding.actionBar.setTitle("资产转让");
                fragmentTransaction.replace(R.id.rl_makeover_publish_up_content, PropertyAlreadyPublishFragment.newInstance(id));
                break;
            case 4:
                mBinding.actionBar.setTitle("公司转让");
                fragmentTransaction.replace(R.id.rl_makeover_publish_up_content, CompanyAlreadyPublishFragment.newInstance(id));
                break;
        }
        fragmentTransaction.commit();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 2){
            finish();
        }
    }
}
